package com.me.modules.sla.controller;

import java.util.List;

import com.me.modules.common.annotation.SysLog;
import com.me.modules.common.controller.BaseController;
import com.me.modules.common.utils.*;
import com.me.modules.sla.service.SlaAlertTempService;
import com.me.modules.sys.service.TimetblInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import com.me.modules.sla.entity.SlaTagartEntity;
import com.me.modules.sla.service.SlaTagartService;

import javax.servlet.http.HttpServletRequest;


/**
 * 服务级别协议规则
 *
 * @author lill
 * @email lill5270@163.com
 * @date 2019-01-11 10:09:37
 */
@Controller
@RequestMapping("/sla/slatagart")
public class SlaTagartController extends BaseController{
	@Autowired
	private SlaTagartService slaTagartService;

	@Autowired
	private SlaAlertTempService slaAlertTempService;

	@Autowired
	private TimetblInfoService timetblInfoService;
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@SysLog("查询工作时间模板")
	public String  list(SlaTagartEntity slaTagart, Model model , HttpServletRequest request){
		//Query query = new Query(params);
		List<SlaTagartEntity> slaTagartList = slaTagartService.queryListByBean(slaTagart);
		model.addAttribute("slaTagartList",slaTagartList);
		model.addAttribute("slaTagart",slaTagart);
		//model.addAttribute("page",page);
		return "sla/sla_tagart/list";
	}


	/**
	 * 信息
	 */
	@RequestMapping("/info")
	//@RequiresPermissions("timetblinfo:info")
	@SysLog("查询工作时间列表")
	public String info( Model model,Long id, HttpServletRequest request){
		SlaTagartEntity slatagart = slaTagartService.queryObject(id);
		model.addAttribute("slatagart",slatagart);
		model.addAttribute("policyList",JsonUtil.getJsonByObj(slaAlertTempService.queryMapList()));
		model.addAttribute("worktimeList",JsonUtil.getJsonByObj(timetblInfoService.queryMapList()));
		return "sla/sla_tagart/edit";
	}



	@RequestMapping(value = "save",method = RequestMethod.POST)
	//@RequiresPermissions("timetblinfo:save")
	@ResponseBody
	public Result save(SlaTagartEntity slaTagart){
//		timetblWorkdate.setBeginDate(new Date());
//		timetblWorkdate.setEndDate(new Date());
		if(slaTagart.getId()==null) {
			slaTagartService.save(slaTagart);
		}else {
			slaTagartService.update(slaTagart);
		}
		//CodeUtils.getCodeName("time_status",slaTagart.getWorkDateType());
		return Result.ok().put("slatagart",slaTagart);
//				.put("timetblWorkdate",timetblWorkdate).put("beginDate", DateUtils.format(timetblWorkdate.getBeginDate(),DateUtils.DATE_TIME_PATTERN))
//				.put("endDate", DateUtils.format(timetblWorkdate.getEndDate(),DateUtils.DATE_TIME_PATTERN)).put("workDateType",CodeUtils.getCodeName("time_status",timetblWorkdate.getWorkDateType()));
	}



	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("slatagart:update")
	public Result update(@RequestBody SlaTagartEntity slaTagart){
		slaTagartService.update(slaTagart);

		return Result.ok();
	}

	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("slatagart:delete")
	public Result delete(@RequestBody Long[] ids){
		slaTagartService.deleteBatch(ids);

		return Result.ok();
	}

}
